Repository navigation
csnode: give BlockChain's consensus-settings members defined defaults - #12
Merged
Merged
Conversation
blockRewardIntegral_/Fraction_, miningCoefficientIntegral_/Fraction_, stakingOn_, miningOn_ and TimeMinStage1_ had no initializer and are not set by the BlockChain constructor. They are written into every quick-start checkpoint (BlockChain_Serializer::save), read back on the --set-bc-top path (Node::init) and emitted by successfullQuickStartEvent. Before any consensus-settings change, or a cache load, has assigned them, that is undefined behaviour. In particular, a checkpoint saved by a slow-starting node before the order-37 activation can carry arbitrary reward settings. Use the same defaults as BlockChain_Serializer::clear(): zero amounts, both flags off, TimeMinStage1 = 500. Nothing changes for members that are assigned before use. Test: BlockChain.ConsensusSettingsHaveDefinedDefaults. It documents the defaults; the old code may pass it by chance, since reading uninitialised memory often yields zero. nodetests: 121/121 pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem (part of path B)
In
BlockChain,blockRewardIntegral_/Fraction_,miningCoefficientIntegral_/Fraction_,stakingOn_,miningOn_andTimeMinStage1_have no initializer, and the constructor does not set them. Yet:BlockChain_Serializer::save);--set-bc-toppath (Node::init);successfullQuickStartEvent.Until a consensus-settings change, or a cache load, assigns them, using them is undefined behaviour. In particular, a checkpoint saved by a slow-starting node before the order-37 activation can carry arbitrary reward settings.
Fix (
blockchain.hpp, +8/-7)Use the same defaults as
BlockChain_Serializer::clear(): zero amounts, both flags off,TimeMinStage1= 500. Nothing changes for members that are assigned before use.Test
BlockChain.ConsensusSettingsHaveDefinedDefaultsdocuments the defaults. The old code may pass it by chance, since uninitialised memory often reads as zero: that is the limit of testing undefined behaviour.nodetests121/121.What this does not do
It does not persist the pending order-37 change. That needs a new checkpoint format, which would force every node into a slow start, and has to be decided separately. Meanwhile, the warning from PR #8 flags a node with a wrong
blockRewardwithin a few blocks.🤖 Generated with Claude Code